#!/bin/bash
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# makeepsfigure.m
# Copyright (C) 2009  K Hartvig Jensen (kare1234@gmail.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
# Description:
# Usage: makeepsfigure.sh filname.tex
# Output: Creates a cropped eps file from the input file using
#         latex filename.tex 
#         dvips -E filename.dvi
#         ps2pdf -B -C -f filename.ps

DVIFILE=`basename $1 .tex`.dvi
PSFILE=`basename $1 .tex`.ps
EPSFILE=`basename $1 .tex`.eps
PDFFILE=`basename $1 .tex`.pdf
PNGFILE=`basename $1 .tex`.png


latex --shell-escape $1
dvips -E $DVIFILE -o
ps2eps -B -C -f $PSFILE
epstopdf $EPSFILE
convert -density 300 $PDFFILE $PNGFILE

